for迴圈
names = [”eddie”, “joanne”, “john”,”sherly”]
for name in names #for..in..的寫法
puts name
end
while迴圈
x = 0
while x < 10 #條件寫在while
puts x
x +=1 #改變條件
end
loop迴圈
i = 0
loop do
puts i
i +=1
break if i > 10 #break結束這回合
end
method式迴圈
1.upto(10) do |i|
puts "hello, ruby #{i}" #從1到10,每圈增加
end
10.downto(1) do |i|
puts "hello, ruby #{i}" #從10到1,每圈減少
end